test for type symmetry
authorØyvind Kolås <ok@src.gnome.org>
Mon, 29 Aug 2005 11:31:47 +0000 (11:31 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Mon, 29 Aug 2005 11:31:47 +0000 (11:31 +0000)
ChangeLog
tests/types.c [new file with mode: 0644]

index bc59154a9337d75ebc4b2e822ae30a3bcea9f8ba..c9250cbea94aa9553bbb816069fc8de64802a36e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-08-29  Øyvind Kolås  <pippin@gimp.org>
+
+       * tests/types.c: added test that tests the symmetry of reference
+       conversions for registered types.
+
 2005-08-29  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-format.c: (each_babl_format_destroy), (format_new),
diff --git a/tests/types.c b/tests/types.c
new file mode 100644 (file)
index 0000000..acda129
--- /dev/null
@@ -0,0 +1,84 @@
+#include "babl.h"
+#include "math.h"
+#include "babl-internal.h"
+
+int OK=1;
+
+double test[] = {    
+  0.0, 0.5, 1.0, 0.1, 0.9, 1.1, -0.1, -2, 2.0, 100, -100, 200, 200
+};
+
+int samples = sizeof(test) / sizeof(test[0]);
+
+static Babl *double_vector_format (void)
+{
+  static Babl *self = NULL;
+  
+  if (!self)
+     self = babl_format_new (
+       babl_model ("Y"),
+       babl_type ("double"),
+       babl_component ("Y"),
+       NULL);
+  return self;
+}
+
+int type_check (Babl *babl,
+                void *userdata)
+{
+  void   *original;
+  double *clipped;
+  void   *destination;
+  double *transformed;
+
+  Babl *fmt;
+
+  
+  original    = babl_calloc (1,babl->type.bits/8 * samples);
+  clipped     = babl_calloc (1,64/8 * samples);
+  destination = babl_calloc (1,babl->type.bits/8 * samples);
+  transformed = babl_calloc (1,64/8 * samples);
+
+  fmt = babl_format_new (babl_model ("Y"),
+                         babl,
+                         babl_component ("Y"),
+                         NULL);
+  
+  babl_process (babl_fish (double_vector_format (), fmt),
+                test, original, samples);
+  babl_process (babl_fish (fmt, double_vector_format ()),
+                original, clipped, samples);
+  babl_process (babl_fish (double_vector_format (), fmt),
+                clipped, destination, samples);
+  babl_process (babl_fish (fmt, double_vector_format ()),
+                destination, transformed, samples);
+  {
+    int i;
+    for (i=0;i<samples;i++)
+      {
+        if (fabs (clipped[i] - transformed[i])>0.00001)
+          babl_log ("%s:  %f %f %f)",
+            babl->instance.name, test[i], clipped[i], transformed[i]
+           );
+          OK=0;
+      }
+  }
+  
+  babl_free (original);
+  babl_free (clipped);
+  babl_free (destination);
+  babl_free (transformed);
+  return 0;
+}
+
+int main (void)
+{
+  babl_init ();
+
+  babl_set_extender (babl_extension_quiet_log ());
+  babl_type_each (type_check, NULL);
+
+  babl_destroy ();
+
+  return !OK;
+}